const myReplace = (str, word, newWord) => {
  const lowerReg = /[a-z]/;
  if (lowerReg.test(word[0])) newWord = newWord[0].toLowerCase() + newWord.slice(1);
  else newWord = newWord[0].toUpperCase() + newWord.slice(1);
  return str.replace(word, newWord);
}

console.log(myReplace("He is Sleeping on the couch", "Sleeping", "sitting"))